home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…stman Always Clicks Twice / ADC Developer CD (1993-01) (''The Postman Always Clicks Twice'')_iso / Dev.CD 199301.iso / Development Platforms / Apple II / Essentials / APW Interfaces / AInclude / M16.Util < prev    next >
Encoding:
Text File  |  1990-11-01  |  18.4 KB  |  681 lines  |  [TEXT/MPS ]

  1. ***********************************************************************
  2. *                                                                      *
  3. *                    Apple //GS Utility Macros                         *
  4. *                              by                                      *
  5. *                          Lou Infeld                                  *
  6. *                                                                      *
  7. *                Copyright Apple Computer, Inc. 1986, 1987             *
  8. *                       All Rights Reserved                            *
  9. *                                                                      *
  10. *        Revision History                                              *
  11. *        ----------------                                              *
  12. *        v1.0R1 (04/29/87) -- First Release                            *
  13. *                             This file is a subset of the old         *
  14. *                                "M16.Utility"                         *                  
  15. *    v2.0R1 (01/22/88) --    First AsmIIGS release                        *
  16. *    v2.0R2 (02/11/88) --    "writelin" renamed "writeline"                *
  17. *    v2.0R3 (03/29/88) --    "|" added to pea instrs to avoid Assembler    *
  18. *                                warning                                    *
  19. *                            "pushlong" was incorrect if &offset was "s"    *
  20. *                                or not specified                        *
  21. *    v2.0R4 (04/14/88) --    "writestr" and "writeline" didn't restore    *
  22. *                            STRING setting                                *
  23. *    v2.0R5 (08/22/88) --    "inc4" and "dec4" redefined to support only    *
  24. *                                positive 4 byte integers                *
  25. *                            "sub4" fixed so that there will not be any    *
  26. *                                truncation warnings generated            *
  27. *                            Pull macros now check for missing parameter *
  28. *                                  or extra parameter                        *
  29. *    v2.0R6 (09/06/88) --    "dec4" fixed to support positive 4 byte        *
  30. *                                integers                                *
  31. *************************************************************************
  32.  
  33. ;............................................................
  34. ;
  35. ;        Pull long (4 bytes) from stack
  36. ;
  37. ;    pulllong address             - pull off stack to address
  38. ;    pulllong addr1,addr2         - pull off stack into 2 places
  39. ;    pulllong [zeropage],offset   - pull off stack and store indirectly             
  40. ;    pulllong                     - pull off stack and leave in A
  41. ;...............................................................
  42.          MACRO
  43. &lab     pulllong &addr1,&addr2
  44. &lab     ANOP
  45.          AIF   C:&addr1=0,.a
  46.          AIF   C:&addr2=0,.b
  47.          LCLC  &C
  48. &C       AMID  &addr1,1,1
  49.          AIF   "&C"="[",.zeropage
  50.          pullword  &addr1
  51.          sta   &addr2
  52.          pullword  &addr1+2
  53.          sta   &addr2+2
  54.          MEXIT
  55. .a
  56.          pullword
  57.          pullword
  58.          MEXIT
  59. .b
  60.          pullword  &addr1
  61.          pullword  &addr1+2
  62.          MEXIT
  63. .zeropage
  64.          ldy   #&addr2
  65.          pullword  &addr1,y
  66.          ldy   #&addr2+2
  67.          pullword  &addr1,y
  68.          MEND
  69. ;...............................................................
  70. ;
  71. ;        Pull 3 bytes from stack
  72. ;
  73. ;    pull3 addr    -- pulls bytes off stack and stores in "loc"
  74. ;...............................................................
  75.          MACRO
  76. &lab     pull3 &addr   
  77. &lab     ANOP
  78.          pull1 &addr
  79.          pullword  &addr+1
  80.          MEND
  81. ;...............................................................
  82. ;
  83. ;        Pull 2 bytes from stack
  84. ;
  85. ;    pullword loc     -- pulls bytes off stack and stores in "loc"
  86. ;    pullword loc,x   -- pulls bytes off stack and stores in "loc,x"
  87. ;    pullword         -- pulls bytes off stack and leaves in A
  88. ;...............................................................
  89.          MACRO
  90. &lab     pullword &SYSOPR
  91. &lab     ANOP
  92.          pla
  93.          AIF   C:&SYSOPR=0,.end
  94.          sta   &SYSOPR
  95. .end
  96.          MEND
  97. ;...............................................................
  98. ;
  99. ;        Pull 1 byte from stack
  100. ;
  101. ;    pull1 loc     -- pulls byte off stack and stores in "loc"
  102. ;    pull1 loc,x   -- pulls byte off stack and stores in "loc,x"
  103. ;    pull1         -- pulls byte off stack and leaves in A
  104. ;...............................................................
  105.          MACRO
  106. &lab     pull1 &SYSOPR
  107. &lab     ANOP
  108.          shortm
  109.          pla
  110.          AIF   C:&SYSOPR=0,.end
  111.          sta   &SYSOPR
  112. .end
  113.          longm
  114.          MEND
  115. ;...............................................................
  116. ;
  117. ;        Push 1 byte onto stack
  118. ;
  119. ;    push1 loc     -- pushes byte onto stack from "loc"
  120. ;    push1 loc,x   -- pushes byte onto stack from "loc,x"
  121. ;    push1 #n      -- pushes constant #n onto stack
  122. ;    push1         -- pushes byte onto stack (from A)
  123. ;...............................................................
  124.          MACRO
  125. &lab     push1 &SYSOPR
  126. &lab     ANOP
  127.          shortm
  128.          AIF   C:&SYSOPR=0,.a
  129.          pushword  &SYSOPR
  130.          AGO   .b
  131. .a
  132.          pushword
  133. .b
  134.          longm
  135.          MEND
  136. ;............................................................
  137. ;
  138. ;        Push long (4 bytes) onto stack
  139. ;
  140. ;    pushlong address             - push contents of address
  141. ;    pushlong address,x           - push contents of address,x
  142. ;    pushlong const,s             - push contents of stack+const    
  143. ;    pushlong #address/const      - push address or constant
  144. ;    pushlong [zeropage],offset   - push using indirect address
  145. ;...............................................................
  146.          MACRO
  147. &lab     pushlong &addr,&offset
  148. &lab     ANOP
  149.          LCLC  &C
  150.          LCLC  &REST
  151. &C       AMID  &addr,1,1
  152.          AIF   "&C"="#",.immediate
  153.          AIF   "&C"="[",.zeropage
  154.          AIF   C:&offset=0,.nooffset
  155.          AIF   "&offset"="s",.stack
  156.          pushword &addr+2,&offset
  157.          pushword &addr,&offset
  158.          MEXIT
  159. .nooffset
  160.          pushword  &addr+2
  161.          pushword  &addr
  162.          MEXIT
  163. .immediate
  164. &REST    AMID  &addr,2,L:&addr-1
  165.          dc    I1'$F4',I2'(&REST)|-16'
  166.          dc    I1'$F4',I2'&REST'
  167.          MEXIT
  168. .stack
  169.          pushword &addr+2,s
  170.          pushword &addr+2,s
  171.          MEXIT
  172. .zeropage
  173.          ldy   #&offset+2
  174.          pushword  &addr,y
  175.          ldy   #&offset
  176.          pushword  &addr,y
  177.          MEND
  178. ;...............................................................
  179. ;
  180. ;        Push 3 bytes onto stack
  181. ;
  182. ;    push3 addr    -- pushes bytes onto stack from "loc"
  183. ;    push3 addr,x  -- pushes bytes onto stack from "loc,x"
  184. ;    push3 #n      -- pushes constant #n onto stack
  185. ;...............................................................
  186.          MACRO
  187. &lab     push3 &addr,®
  188. &lab     ANOP
  189.          LCLC  &C
  190.          LCLC  &REST
  191. &C       AMID  &addr,1,1
  192. &REST    AMID  &addr,2,L:&addr
  193.          AIF   C:®>0,.indexed
  194.          AIF   "&C"="#",.immediate
  195.          lda   &addr+1
  196.          pha
  197.          AGO   .a
  198. .immediate
  199.          lda   #(&REST)|-8
  200.          pha
  201. .a
  202.          phb
  203.          lda   &addr
  204.          sta   1,s
  205.          MEXIT
  206. .indexed
  207.          lda   &addr+1,®
  208.          pha
  209.          phb
  210.          lda   &addr,®
  211.          sta   1,s
  212.          MEND
  213. ;...............................................................
  214. ;
  215. ;        Push 2 bytes onto stack
  216. ;
  217. ;    pushword loc     -- pushes bytes onto stack from "loc"
  218. ;    pushword loc,x   -- pushes bytes onto stack from "loc,x"
  219. ;    pushword #n      -- pushes constant #n onto stack
  220. ;    pushword         -- pushes bytes onto stack (from A)
  221. ;...............................................................
  222.          MACRO
  223. &lab     pushword  &SYSOPR
  224. &lab     ANOP
  225.          AIF   C:&SYSOPR=0,.b
  226.          LCLC  &C
  227. &C       AMID  "&SYSOPR",1,1
  228.          AIF   ("&C"="#").AND.(S:LONGA),.immediate
  229.          lda   &SYSOPR
  230.          pha
  231.          MEXIT
  232. .b
  233.          pha
  234.          MEXIT
  235. .immediate
  236.          LCLC  &REST
  237.          LCLA  &BL
  238. &BL      ASEARCH "&SYSOPR"," ",1
  239.          AIF   &BL>0,.a
  240. &BL      SETA  L:&SYSOPR+1
  241. .a
  242. &REST    AMID  "&SYSOPR",2,&BL-2
  243.          dc    I1'$F4',I2'&REST'
  244.          MEND
  245. ;...............................................................
  246. ;
  247. ;        Add 2 byte integers
  248. ;
  249. ;    add loc1,loc2,loc3 - adds "loc1" to "loc2" and stores in "loc3"
  250. ;    add loc1,loc2      - adds "loc1" to "loc2" and leaves in A
  251. ;    add ,loc2,loc3     - adds A with "loc2" and stores in "loc3" 
  252. ;
  253. ;        "loc1" and "loc2" can be constants
  254. ;...............................................................
  255.          MACRO
  256. &lab     add   &a1,&a2,&a3
  257. &lab     ANOP
  258.          AIF   C:&a1=0,.a
  259.          lda   &a1
  260. .a
  261.          clc
  262.          adc   &a2
  263.          AIF   C:&a3=0,.b
  264.          sta   &a3
  265. .b
  266.          MEND
  267. ;...............................................................
  268. ;
  269. ;        Add 4 byte integers
  270. ;
  271. ;    add4 loc1,loc2,loc3 - adds "loc1" to "loc2" and stores in "loc3"
  272. ;    add4 ,loc2,loc3     - adds A to "loc2" and stores in "loc3"
  273. ;
  274. ;        "loc1" and "loc2" can be constants
  275. ;...............................................................
  276.          MACRO
  277. &lab     add4  &a1,&a2,&a3
  278. &lab     ANOP
  279.          LCLC  &C1
  280.          LCLC  &C2
  281.          LCLC  &REST1
  282.          LCLC  &REST2
  283. &C2      AMID  &a2,1,1
  284. &REST2   AMID  &a2,2,L:&a2-1
  285.          AIF   C:&a1=0,.a
  286. &C1      AMID  &a1,1,1
  287. &REST1   AMID  &a1,2,L:&a1-1
  288.          lda   &a1
  289. .a
  290.          clc
  291.          adc   &a2
  292.          sta   &a3
  293.          AIF   C:&a1>0,.b
  294.          lda   #0
  295.          AGO   .d
  296. .b
  297.          AIF   "&C1"="#",.c
  298.          lda   &a1+2
  299.          AGO   .d
  300. .c
  301.          lda   #^&REST1
  302. .d
  303.          AIF   "&C2"="#",.e
  304.          adc   &a2+2
  305.          AGO   .f
  306. .e
  307.          adc   #^&REST2
  308. .f
  309.          sta   &a3+2
  310.          MEND
  311. ;...............................................................
  312. ;
  313. ;        Increment a positive 4 byte integer
  314. ;
  315. ;    inc4 loc - increments "loc"
  316. ;...............................................................
  317.          MACRO
  318. &lab     inc4  &a1
  319. &lab     ANOP
  320.          inc   &a1
  321.          bne   ~a&SYSCNT
  322.          inc   &a1+2
  323. ~a&SYSCNT ANOP
  324.          MEND
  325. ;...............................................................
  326. ;
  327. ;        Subtract 2 byte integers
  328. ;
  329. ;    sub loc1,loc2,loc3 - subtracts "loc2" from "loc1" and stores in "loc3"
  330. ;    sub loc1,loc2      - subtracts "loc2" from "loc1" and leaves in A
  331. ;    sub ,loc2,lo3      - subtracts "loc2" from A and stores in "loc3" 
  332. ;
  333. ;        "loc1" and "loc2" can be constants
  334. ;...............................................................
  335.          MACRO
  336. &lab     sub   &a1,&a2,&a3
  337. &lab     ANOP
  338.          AIF   C:&a1=0,.a
  339.          lda   &a1
  340. .a
  341.          sec
  342.          sbc   &a2
  343.          AIF   C:&a3=0,.b
  344.          sta   &a3
  345. .b
  346.          MEND
  347. ;...............................................................
  348. ;
  349. ;        Subtract 4 byte integers
  350. ;
  351. ;    sub4 loc1,loc2,loc3 - subtracts "loc2" from "loc1" and stores in "loc3"
  352. ;    sub4 ,loc2,loc3     - subtracts "loc2" from A and stores in "loc3"
  353. ;...............................................................
  354.          MACRO
  355. &lab     sub4  &a1,&a2,&a3
  356. &lab     ANOP
  357.          LCLC  &C1
  358.          LCLC  &C2
  359.          LCLC  &REST1
  360.          LCLC  &REST2
  361. &C2      AMID  &a2,1,1
  362. &REST2   AMID  &a2,2,L:&a2-1
  363.          AIF   C:&a1=0,.a
  364. &C1      AMID  &a1,1,1
  365. &REST1   AMID  &a1,2,L:&a1-1
  366.          lda   &a1
  367. .a
  368.          sec
  369.          sbc   &a2
  370.          sta   &a3
  371.          AIF   C:&a1>0,.b
  372.          lda   #0
  373.          AGO   .d
  374. .b
  375.          AIF   "&C1"="#",.c
  376.          lda   &a1+2
  377.          AGO   .d
  378. .c
  379.          lda   #^&REST1
  380. .d
  381.          AIF   "&C2"="#",.e
  382.          sbc   &a2+2
  383.          AGO   .f
  384. .e
  385.          sbc   #^&REST2
  386. .f
  387.          sta   &a3+2
  388.          MEND
  389. ;...............................................................
  390. ;
  391. ;        Decrement a positive 4 byte integer
  392. ;
  393. ;    dec4 loc - decrements "loc"
  394. ;...............................................................
  395.          MACRO
  396. &lab     dec4  &a1
  397. &lab     ANOP
  398.          pha
  399.          sec
  400.          lda   &a1
  401.          sbc   #1
  402.          bcs   ~a&SYSCNT
  403.          dec   &a1+2
  404. ~a&SYSCNT sta   &a1
  405.          pla
  406.          MEND
  407. ;...............................................................
  408. ;
  409. ;        Define string
  410. ;
  411. ;        Generates a Pascal type of string
  412. ;...............................................................
  413.          MACRO
  414. &lab     str   &string
  415. &lab     dc    i1'L:&string',C'&string'
  416.          MEND
  417. ;...............................................................
  418. ;
  419. ;        Define pointer
  420. ;...............................................................
  421.          MACRO
  422. &lab     dp    &pointer
  423. &lab     dc    i4'&pointer'
  424.          MEND
  425. ;...............................................................
  426. ;
  427. ;        Left Shift 4 bytes
  428. ;
  429. ;        asl4  loc,#n                   ;n is shift count (pos)
  430. ;        asl4  loc,lnum                 ;lnum contains shift count (pos)
  431. ;        asl4  loc                      ;X contains shift count (pos)
  432. ;...............................................................
  433.          MACRO
  434. &lab     asl4  &loc,&num
  435. &lab     ANOP
  436.          lda   &loc+2
  437.          AIF   C:&num=0,.a
  438.          ldx   &num
  439. .a
  440. ~a&SYSCNT asl  a
  441.          asl   &loc
  442.          adc   #0
  443.          dex
  444.          bne   ~a&SYSCNT
  445.          sta   &loc+2
  446.          MEND
  447. ;...............................................................
  448. ;
  449. ;        Right Shift 4 bytes
  450. ;
  451. ;        lsr4  loc,#n                   ;n is shift count (pos)
  452. ;        lsr4  loc,lnum                 ;lnum contains shift count (pos)
  453. ;        lsr4  loc                      ;X contains shift count (neg)
  454. ;...............................................................
  455.          MACRO
  456. &lab     lsr4  &loc,&num
  457. &lab     ANOP
  458.          AIF   C:&num=0,.a
  459.          lda   &num
  460.          eor   #$FFFF
  461.          clc
  462.          adc   #1
  463.          tax
  464. .a
  465.          lda   &loc
  466. ~a&SYSCNT lsr  a
  467.          lsr   &loc+2
  468.          bcc   ~b&SYSCNT
  469.          ora   #$8000
  470. ~b&SYSCNT inx
  471.          bne   ~a&SYSCNT
  472.          sta   &loc
  473.          MEND
  474. ;...............................................................
  475. ;
  476. ;        Turn on native mode
  477. ;
  478. ;    The processor is put into "native" mode.  8 bit or 16 bit
  479. ;    mode can be specified by using "short" or "long" as the
  480. ;    parameter.  If no parameter is specified, "long" is assumed
  481. ;...............................................................
  482.          MACRO
  483. &lab     native &mode
  484. &lab     ANOP
  485.          clc
  486.          xce
  487.          AIF C:&mode=0,.a
  488.          &mode
  489.          MEXIT
  490. .a
  491.          long
  492.          MEND
  493. ;...............................................................
  494. ;
  495. ;        Turn on emulation mode
  496. ;
  497. ;    The processor is put into "emulation" mode.
  498. ;...............................................................
  499.          MACRO
  500. &lab     emulation
  501. &lab     ANOP
  502.          sec
  503.          xce
  504.          longa off
  505.          longi off
  506.          MEND
  507. ;...............................................................
  508. ;
  509. ;        Set Memory & registers to 16 bits
  510. ;...............................................................
  511.          MACRO
  512. &lab     long
  513. &lab     ANOP
  514.          rep   #%00110000
  515.          longa on
  516.          longi on
  517.          MEND
  518. ;...............................................................
  519. ;
  520. ;        Set Memory & A register to 16 bits
  521. ;...............................................................
  522.          MACRO
  523. &lab     longm
  524. &lab     ANOP
  525.          rep   #%00100000
  526.          longa on
  527.          MEND
  528. ;...............................................................
  529. ;
  530. ;        Set X & Y registers to 16 bits
  531. ;...............................................................
  532.          MACRO
  533. &lab     longx
  534. &lab     ANOP
  535.          rep   #%00010000
  536.          longi on
  537.          MEND
  538. ;...............................................................
  539. ;
  540. ;        Set Memory & registers to 8 bits
  541. ;...............................................................
  542.          MACRO
  543. &lab     short
  544. &lab     ANOP
  545.          sep   #%00110000
  546.          longa off
  547.          longi off
  548.          MEND
  549. ;...............................................................
  550. ;
  551. ;        Set Memory & A register to 8 bits
  552. ;...............................................................
  553.          MACRO
  554. &lab     shortm
  555. &lab     ANOP
  556.          sep   #%00100000
  557.          longa off
  558.          MEND
  559. ;...............................................................
  560. ;
  561. ;        Set X & Y registers to 8 bits
  562. ;...............................................................
  563.          MACRO
  564. &lab     shortx
  565. &lab     ANOP
  566.          sep   #%00010000
  567.          longi off
  568.          MEND
  569. ;...............................................................
  570. ;
  571. ;        Write string
  572. ;
  573. ;        writestr loc     - string at loc "loc"
  574. ;        writestr #'ABC'  - string='ABC'
  575. ;        writestr         - A,Y has loc of string         
  576. ;...............................................................
  577.  
  578.          MACRO
  579. &lab     writestr &addr
  580. &lab     ANOP
  581.          AIF   C:&addr=0,.c
  582.          lclc  &char
  583. &char    amid  &addr,1,1
  584.          AIF   "&char"="#",.a
  585.          pea   &addr|-16
  586.          pea   &addr
  587.          ago   .b
  588. .a
  589.          lclc  &str
  590. &str     amid  &addr,3,L:&addr-3
  591.          bra   ~b&SYSCNT
  592. ~a&SYSCNT dc   i1'L:&str',C'&str'
  593. ~b&SYSCNT pea  ~a&SYSCNT|-16
  594.          pea   ~a&SYSCNT
  595. .b
  596.          ldx   #$1C0C
  597.          jsl   $E10000
  598.          MEXIT
  599. .c
  600.          phy
  601.          pha
  602.          AGO   .b
  603.          MEND
  604. ;...............................................................
  605. ;
  606. ;        Write line (string+CR)
  607. ;
  608. ;        writeln loc     - string at loc "loc"
  609. ;        writeln #'ABC'  - string='ABC'
  610. ;        writeln         - CR only
  611. ;
  612. ;...............................................................
  613.  
  614.          MACRO
  615. &lab     writeln &addr
  616. &lab     ANOP
  617.          AIF   C:&addr=0,.c
  618.          lclc  &char
  619. &char    amid  &addr,1,1
  620.          AIF   "&char"="#",.a
  621.          pea   &addr|-16
  622.          pea   &addr
  623.          ago   .b
  624. .a
  625.          lclc  &str
  626. &str     amid  &addr,3,L:&addr-3
  627.          bra   ~b&SYSCNT
  628. ~a&SYSCNT dc   I1'L:&str',C'&str'
  629. ~b&SYSCNT pea  ~a&SYSCNT|-16
  630.          pea   ~a&SYSCNT
  631. .b
  632.          ldx   #$1A0C
  633. ~c&SYSCNT jsl  $E10000
  634.          MEXIT
  635. .c
  636.          pea   +(~c&SYSCNT+1)|-16
  637.          pea   ~c&SYSCNT+1
  638.          AGO   .b
  639.          MEND
  640. ;...............................................................
  641. ;
  642. ;        Write character
  643. ;
  644. ;        writech          - char in A register
  645. ;        writech #'A'     - char='A'
  646. ;        writech ch,x     - char in loc "ch,x"
  647. ;...............................................................
  648.  
  649.          MACRO
  650. &lab     writech &SYSOPR
  651. &lab     ANOP
  652.          AIF   C:&SYSOPR=0,.a
  653.          lda   &SYSOPR
  654. .a
  655.          pha
  656.          ldx   #$180C
  657.          jsl   $E10000
  658.          MEND
  659. ;...............................................................
  660. ;
  661. ;              Read a char from keyboard
  662. ;
  663. ;        readch addr     - char stored in "addr"
  664. ;        readch          - char left in A register
  665. ;
  666. ;...............................................................
  667.  
  668.          MACRO
  669. &lab     readch &SYSOPR
  670. &lab     ANOP
  671.          pea   0
  672.          pea   1
  673.          ldx   #$220C
  674.          jsl   $E10000
  675.          pla
  676.          AIF   C:&SYSOPR=0,.a
  677.          sta   &SYSOPR
  678. .a
  679.          MEND
  680.  
  681.